package com.xgzit.xgzmall.member.web;

import com.alibaba.fastjson.TypeReference;
import com.esotericsoftware.minlog.Log;
import com.xgzit.common.utils.PageUtils;
import com.xgzit.common.utils.R;
import com.xgzit.xgzmall.member.feign.OrderFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author xgz
 * @Date 2021-07-10 14:05
 */
@Controller
public class MemberWebController {

    @Autowired
    OrderFeignService orderFeignService;

    @GetMapping("/memberOrder.html")
    public String memberOrderPage(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                  @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                  Model model){
        // todo 获取支付宝给我们传来的数据

        // 查出当前登录的用户的所有订单列表数据
        Map<String, Object> page = new HashMap<>(4);
        page.put("page", String.valueOf(pageNum));
        page.put("limit", String.valueOf(pageSize));
        // 页面访问会自动携带cookie  而feign会丢失这些  需要重新设置feign
        R r = orderFeignService.listWithItem(page);
        PageUtils data = null;
        if (r.getCode()==0){
            data = r.getData(new TypeReference<PageUtils>() {
            });
            Log.info(data.toString());
        }
        model.addAttribute("orders", data);
        return "orderList";
    }
}
